{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Garimpagem de Dados\n",
    "\n",
    "## Aula 4 - Exercídio de Classificação com kNN\n",
    "\n",
    "13/10/2017"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Dataset:** Titanic: Machine Learning from Disaster\n",
    "\n",
    "https://www.kaggle.com/c/titanic/data\n",
    "\n",
    "Partindo da aula passada:\n",
    "\n",
    "1. Atualizar a função que mede a distância euclidiana para o pacote do scikit-learn \n",
    "\n",
    "2. Implementar uma função que selecione os k vizinhos mais próximos (k > 1)\n",
    "\n",
    "3. Implementar uma função que recebe os k vizinhos mais próximos e determinar a classe correta\n",
    "\n",
    "4. Transformar as features categoricas em numéricas (tip: pandas ou scikit-learn)\n",
    "\n",
    "5. Analisar a necessidade de normalizar as features numéricas (tip: pandas ou scikit-learn)\n",
    "\n",
    "6. Selecionar as features baseada na correlação (tip: pandas)\n",
    "\n",
    "7. Separar o dataset em treino (75%) / teste (25%) / validação (10% do treino)\n",
    "\n",
    "4. Execute o classificador para 30 k's pulando de 4 em 4 e apresente todas as acurácias utilizando o dataset de validação (Qual o melhor k?) [plotar um gráfico com os resultados]\n",
    "\n",
    "5. Executar o classificador para o melhor k encontrado utilizando o dataset de teste e apresentar um relatório da precisão (tip: scikit-learn) [plotar um gráfico com os resultados]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Importando as bibliotecas\n",
    "from sklearn.metrics import classification_report, accuracy_score\n",
    "from sklearn.neighbors import DistanceMetric\n",
    "from sklearn.preprocessing import LabelEncoder, MinMaxScaler\n",
    "from sklearn.model_selection import train_test_split\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "class KNNClassifier(object):\n",
    "    def __init__(self):\n",
    "        self.X_train = None\n",
    "        self.y_train = None\n",
    "        self.dist = DistanceMetric.get_metric(\"euclidean\")\n",
    "\n",
    "    def euc_distance(self,row, point):\n",
    "        return self.dist.pairwise([row], [point])[0,0]\n",
    "        \n",
    "    def closest(self, row, K):\n",
    "        \"\"\"\n",
    "        Retorna a classe respondente ao ponto mais próximo do dataset de treino.\\\n",
    "        É um exemplo de implementação do kNN com k=1.\n",
    "        \"\"\"\n",
    "        allDist = [self.euc_distance(row, points) for points in self.X_train]\n",
    "        closests = np.argsort(allDist)[:K]\n",
    "        return self.y_train[closests]\n",
    "\n",
    "    def fit(self, training_data, training_labels):\n",
    "        self.X_train = training_data\n",
    "        self.y_train = training_labels\n",
    "\n",
    "    def predict(self, to_classify, K):\n",
    "        predictions = []\n",
    "        for row in to_classify:\n",
    "            labels = np.argmax(np.bincount(self.closest(row, K)))\n",
    "            predictions.append(labels)\n",
    "        return predictions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PassengerId</th>\n",
       "      <th>Survived</th>\n",
       "      <th>Pclass</th>\n",
       "      <th>Name</th>\n",
       "      <th>Sex</th>\n",
       "      <th>Age</th>\n",
       "      <th>SibSp</th>\n",
       "      <th>Parch</th>\n",
       "      <th>Ticket</th>\n",
       "      <th>Fare</th>\n",
       "      <th>Cabin</th>\n",
       "      <th>Embarked</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Braund, Mr. Owen Harris</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>A/5 21171</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>PC 17599</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C85</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>Heikkinen, Miss. Laina</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>STON/O2. 3101282</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>113803</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>C123</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Allen, Mr. William Henry</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>373450</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   PassengerId  Survived  Pclass  \\\n",
       "0            1         0       3   \n",
       "1            2         1       1   \n",
       "2            3         1       3   \n",
       "3            4         1       1   \n",
       "4            5         0       3   \n",
       "\n",
       "                                                Name     Sex   Age  SibSp  \\\n",
       "0                            Braund, Mr. Owen Harris    male  22.0      1   \n",
       "1  Cumings, Mrs. John Bradley (Florence Briggs Th...  female  38.0      1   \n",
       "2                             Heikkinen, Miss. Laina  female  26.0      0   \n",
       "3       Futrelle, Mrs. Jacques Heath (Lily May Peel)  female  35.0      1   \n",
       "4                           Allen, Mr. William Henry    male  35.0      0   \n",
       "\n",
       "   Parch            Ticket     Fare Cabin Embarked  \n",
       "0      0         A/5 21171   7.2500   NaN        S  \n",
       "1      0          PC 17599  71.2833   C85        C  \n",
       "2      0  STON/O2. 3101282   7.9250   NaN        S  \n",
       "3      0            113803  53.1000  C123        S  \n",
       "4      0            373450   8.0500   NaN        S  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Carregando os dados\n",
    "data_train = pd.read_csv(\"train.csv\")\n",
    "data_train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Inputando dados faltosos em Idade, usando a média\n",
    "data_train[\"Age\"] = data_train.Age.fillna(data_train.Age.mean())\n",
    "\n",
    "# Remove linhas com dados faltosos (falta de informação e impossibilidade de inputação)\n",
    "data_train = data_train.dropna(axis=0, how=\"any\")\n",
    "\n",
    "# Remove os atributos \"Name\" e \"Ticket\" pois, de forma crua, eles provavelmente\n",
    "# não oferecem informações que permitam inferir se a pessoa sobreviveu ou não\n",
    "data_train.drop(labels=[\"Name\", \"Ticket\"], axis=1, inplace=True)\n",
    "\n",
    "# Separando entradas/saída \n",
    "X_train = data_train.loc[:,\"Pclass\":]\n",
    "y_train = data_train[[\"Survived\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Pclass</th>\n",
       "      <th>Sex</th>\n",
       "      <th>Age</th>\n",
       "      <th>SibSp</th>\n",
       "      <th>Parch</th>\n",
       "      <th>Fare</th>\n",
       "      <th>Cabin</th>\n",
       "      <th>Embarked</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>80</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>54</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>54.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>51.8625</td>\n",
       "      <td>128</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>16.7000</td>\n",
       "      <td>144</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>58.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>26.5500</td>\n",
       "      <td>48</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Pclass  Sex   Age  SibSp  Parch     Fare  Cabin  Embarked\n",
       "1        1    0  38.0      1      0  71.2833     80         0\n",
       "3        1    0  35.0      1      0  53.1000     54         2\n",
       "6        1    1  54.0      0      0  51.8625    128         2\n",
       "10       3    0   4.0      1      1  16.7000    144         2\n",
       "11       1    0  58.0      0      0  26.5500     48         2"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Transformando dados categoricos\n",
    "LE = LabelEncoder()\n",
    "for feature in [\"Sex\", \"Cabin\", \"Embarked\"]:\n",
    "    X_train[[feature]] = X_train[[feature]].astype(str)\n",
    "    LE.fit(X_train.loc[:,feature])\n",
    "    X_train[[feature]] = LE.transform(X_train.loc[:,feature])\n",
    "    \n",
    "X_train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Pclass</th>\n",
       "      <th>Sex</th>\n",
       "      <th>Age</th>\n",
       "      <th>SibSp</th>\n",
       "      <th>Parch</th>\n",
       "      <th>Fare</th>\n",
       "      <th>Cabin</th>\n",
       "      <th>Embarked</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Pclass</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>-0.060014</td>\n",
       "      <td>-0.287184</td>\n",
       "      <td>-0.086972</td>\n",
       "      <td>0.056288</td>\n",
       "      <td>-0.311740</td>\n",
       "      <td>0.494000</td>\n",
       "      <td>0.170303</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sex</th>\n",
       "      <td>-0.060014</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.167361</td>\n",
       "      <td>-0.152552</td>\n",
       "      <td>-0.110574</td>\n",
       "      <td>-0.137185</td>\n",
       "      <td>-0.083768</td>\n",
       "      <td>0.096805</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Age</th>\n",
       "      <td>-0.287184</td>\n",
       "      <td>0.167361</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-0.139881</td>\n",
       "      <td>-0.246928</td>\n",
       "      <td>-0.076680</td>\n",
       "      <td>-0.125576</td>\n",
       "      <td>-0.090462</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SibSp</th>\n",
       "      <td>-0.086972</td>\n",
       "      <td>-0.152552</td>\n",
       "      <td>-0.139881</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.262348</td>\n",
       "      <td>0.291777</td>\n",
       "      <td>0.056745</td>\n",
       "      <td>0.002228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Parch</th>\n",
       "      <td>0.056288</td>\n",
       "      <td>-0.110574</td>\n",
       "      <td>-0.246928</td>\n",
       "      <td>0.262348</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.384970</td>\n",
       "      <td>0.001291</td>\n",
       "      <td>0.061455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Fare</th>\n",
       "      <td>-0.311740</td>\n",
       "      <td>-0.137185</td>\n",
       "      <td>-0.076680</td>\n",
       "      <td>0.291777</td>\n",
       "      <td>0.384970</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-0.262818</td>\n",
       "      <td>-0.239213</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cabin</th>\n",
       "      <td>0.494000</td>\n",
       "      <td>-0.083768</td>\n",
       "      <td>-0.125576</td>\n",
       "      <td>0.056745</td>\n",
       "      <td>0.001291</td>\n",
       "      <td>-0.262818</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.231418</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Embarked</th>\n",
       "      <td>0.170303</td>\n",
       "      <td>0.096805</td>\n",
       "      <td>-0.090462</td>\n",
       "      <td>0.002228</td>\n",
       "      <td>0.061455</td>\n",
       "      <td>-0.239213</td>\n",
       "      <td>0.231418</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            Pclass       Sex       Age     SibSp     Parch      Fare  \\\n",
       "Pclass    1.000000 -0.060014 -0.287184 -0.086972  0.056288 -0.311740   \n",
       "Sex      -0.060014  1.000000  0.167361 -0.152552 -0.110574 -0.137185   \n",
       "Age      -0.287184  0.167361  1.000000 -0.139881 -0.246928 -0.076680   \n",
       "SibSp    -0.086972 -0.152552 -0.139881  1.000000  0.262348  0.291777   \n",
       "Parch     0.056288 -0.110574 -0.246928  0.262348  1.000000  0.384970   \n",
       "Fare     -0.311740 -0.137185 -0.076680  0.291777  0.384970  1.000000   \n",
       "Cabin     0.494000 -0.083768 -0.125576  0.056745  0.001291 -0.262818   \n",
       "Embarked  0.170303  0.096805 -0.090462  0.002228  0.061455 -0.239213   \n",
       "\n",
       "             Cabin  Embarked  \n",
       "Pclass    0.494000  0.170303  \n",
       "Sex      -0.083768  0.096805  \n",
       "Age      -0.125576 -0.090462  \n",
       "SibSp     0.056745  0.002228  \n",
       "Parch     0.001291  0.061455  \n",
       "Fare     -0.262818 -0.239213  \n",
       "Cabin     1.000000  0.231418  \n",
       "Embarked  0.231418  1.000000  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Verificando a Matriz de Correlação (Numérica)\n",
    "corrMatrix = X_train.corr()\n",
    "corrMatrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAAN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zvxxrdT/2+EBCFB9IiOIDCVF8ICGKDyRE\n8YGEKD6QEMUHEqL4QELzFt/2Btt7Z32csH1zjcUBKGPeU3Yj4oCkKyXJ9pCkI5J2FF4XgIJ6PdTf\nIulgRBwqsRgAdfRa/G2S7i2xEAD1tC5+c039GyR9+12+/vbsvJPMzgMGWS97/K2S9kTET+f64jtm\n5y1hdh4wyHop/o3iMB84L7QqfjMW+zpJD5ZdDoAa2o7QmpR0QeG1AKiEM/eAhCg+kBDFBxKi+EBC\nFB9IiOIDCVF8ICGKDyRE8YGEHNH/uXO2j0layHv2V0s63uflDEIWeeTVylsXERfOd6cixV8o27si\nYtP5lkUeeYOWx6E+kBDFBxIatOLffp5mkUfeQOUN1HN8AHUM2h4fQAUUH0iI4gMJUXwgIYoPJPQ/\nF438STzqLtgAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f1e23e48208>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Verificando a Matriz de Correlação (Plotagem)\n",
    "plt.matshow(corrMatrix.values)\n",
    "plt.show()\n",
    "\n",
    "# Removeremos o atributo \"Cabin\", apesar de a correlação não ser realmente muito forte\n",
    "data_train.drop(labels=[\"Cabin\"], axis=1, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.          0.          0.46889226 ...,  0.13913574  0.55172414  0.        ]\n",
      " [ 0.          0.          0.43095599 ...,  0.1036443   0.37241379  1.        ]\n",
      " [ 0.          1.          0.67121902 ...,  0.10122886  0.88275862  1.        ]\n",
      " ..., \n",
      " [ 0.          0.          0.69650986 ...,  0.16231419  0.47586207  0.        ]\n",
      " [ 0.          0.          0.22862924 ...,  0.0585561   0.2         1.        ]\n",
      " [ 0.          1.          0.31714719 ...,  0.0585561   0.40689655  0.        ]]\n"
     ]
    }
   ],
   "source": [
    "# Normalizando as features numéricas\n",
    "X_train = MinMaxScaler().fit_transform(X_train)\n",
    "\n",
    "np.disp(X_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Separação dos Datasets\n",
    "# Treino(75%) / Teste(25%)\n",
    "X_train, X_test, y_train, y_test = train_test_split(X_train, y_train.values.flatten(), test_size=0.25)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# Optimal number of neighbors:  55\n",
      "# Score:  93.75 %\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAD8CAYAAABw1c+bAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXuwHNV54H+frnQlJCQkga5AL6QBDMjYCHMtCBZPTWzI\nw6ydpAoSl7PeuCiq7MS75UqM10mqUltblSrHW0mV8RIqy/oRB8qVmDUmGOwRL4MfSIAACRAWo7es\nqwcXhN7o6ts/vumoNZq50z3TPTPd/f2qbt2Znu6ec+bxm9PfOec7oqo4juM4xWFCrwvgOI7jdBcX\nv+M4TsFw8TuO4xQMF7/jOE7BcPE7juMUDBe/4zhOwXDxO47jFAwXv+M4TsGIJH4RuVlENojIRhG5\nq8Hjs0TkQRF5WUSeE5HLQo9tFpFXRGStiKxJsvCO4zhOfKTVzF0RGQDeAH4T2A6sBm5X1VdD+3wV\nOKCqfyMilwB3q+rK2mObgWFV3Ru1UOecc44uXrw4ZlUcx3GKy/PPP79XVedE2XdihH2WAxtVtQog\nIg8AtwKvhvZZCvwtgKq+LiKLRWSuqo7EK7qxePFi1qzxiwPHcZyoiMiWqPtGCfXMB7aF7m+vbQvz\nEvDJ2pMvB84HFtQeU6AiIs+LyB3jFPoOEVkjImv27NkTtfyO4zhOTJL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9E5D8DvwP8kZ4ca594fbIi/tXA\nRSKyREQGsY6Oh3pcptiIiGCx49dU9X+FHnoI+OPa7T8GftDtsrWDqn5ZVReo6mLsPXlcVT9FRusD\noKq7gG0icnFt00rgVbJbp63A1SIytfb5W4n1LWW1PmGa1eEh4DYRmSwiS4CLgOd6UL5YiMjNWNj0\n46p6KPRQ8vVR1Uz8Ab+F9XS/CXyl1+Vpsw4rsMvRl4G1tb/fAs7GRiX8CqgAs3td1jbqdgPwcO12\npusDLAPW1N6n/wfMynKdgL8BXgfWAd8BJmetPsD9WB/Fe9hV2Z+MVwfgKzVXbABu6XX5I9ZnIxbL\nD9xwT1r18Zm7juM4BSMroR7HcRwnIVz8juM4BcPF7ziOUzBc/I7jOAXDxe84jlMwXPyO4zgFw8Xv\nOI5TMFz8juM4BeP/A+7FexQKBKu9AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f1e23e13128>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Cross-Validation\n",
    "knn = KNNClassifier()\n",
    "knn.fit(X_train, y_train)\n",
    "\n",
    "score_cv = []\n",
    "k_cv = np.arange(3, 123, 4)  # O K=1 foi removido pois estava causando over-fitting\n",
    "\n",
    "for k in k_cv:\n",
    "    _, X_cv, _, Y_cv = train_test_split(X_train, y_train, test_size=0.1)\n",
    "    y_pred_cv = knn.predict(X_cv, k) \n",
    "    score_cv.append(accuracy_score(y_pred=y_pred_cv, y_true=Y_cv))\n",
    "    \n",
    "optK = k_cv[np.argmax(score_cv)]\n",
    "print(\"# Optimal number of neighbors: \", optK)\n",
    "print(\"# Score: \", np.max(score_cv)*100, \"%\")\n",
    "    \n",
    "plt.figure()\n",
    "plt.plot(k_cv, score_cv, 'r-')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              precision    recall  f1-score   support\n",
      "\n",
      "    Survived       0.68      0.75      0.71        20\n",
      "Not Survived       0.83      0.77      0.80        31\n",
      "\n",
      " avg / total       0.77      0.76      0.77        51\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Testando o K ótimo\n",
    "y_pred = knn.predict(X_test, optK)\n",
    "print(classification_report(y_test, y_pred, target_names=[\"Survived\", \"Not Survived\"]))"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
